﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using haptic.src.engine;
using haptic.src.engine.render;
using haptic.src.engine.animation;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using haptic.src.engine.core;

namespace haptic.src.components
{
    [Serializable]
    public class cAutomate : Component
    {
        #region Constructors
        public cAutomate(){}
        public cAutomate(Entity oOwner) : base(oOwner) { }
        #endregion

        #region Load
        public override Result Load(haptic.src.engine.Scene oGame, ContentManager oContent)
        {
            if (m_sFilePath != null)
            {
                Automate oAutomate = Automate.Deserialize(oGame, m_sFilePath);
                oAutomate.Load(oContent);
                m_oAutomateInstance = oAutomate.CreateInstance();
            }
            return Result.Success;
        }
        #endregion

        #region Update
        public void SetFacingDirection(Vector2 vDirection)
        {
            if (m_oAutomateInstance != null)
                m_oAutomateInstance.m_oContext.m_vFacingDirection = vDirection;
        }
        public override void Update(Microsoft.Xna.Framework.GameTime oTime)
        {
            if (m_oAutomateInstance != null)
                m_oAutomateInstance.Update(oTime);
            base.Update(oTime);
        }
        #endregion

        #region Draw
        public override void Draw(Renderer oRenderer, Microsoft.Xna.Framework.GameTime oTime)
        {
            if (m_oAutomateInstance != null)
            {
                m_oAutomateInstance.m_oContext.m_vPosition = m_oEntity.m_vPosition;
                m_oAutomateInstance.Draw(oRenderer);
            }
            base.Draw(oRenderer, oTime);
        }
        #endregion

        #region Attributes
        [XmlIgnore]
        public AutomateInstance m_oAutomateInstance;
        public string m_sFilePath;
        #endregion
    }
}
